package com.allenja.eleviewer;

import java.io.IOException;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton;

public class SettingsViewActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings_view);
        
        final ToggleButton contoursToggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
        final ToggleButton polygonsToggleButton = (ToggleButton) findViewById(R.id.toggleButton2);
        final Button modelDirChooserButton = (Button) findViewById(R.id.button1);
        
        contoursToggleButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				if (contoursToggleButton.isChecked()) {
					polygonsToggleButton.setChecked(false);
					MyRenderer.setModelViewMode("Contours");
				}
			}
		});        
        
        polygonsToggleButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				if (polygonsToggleButton.isChecked()) {
					contoursToggleButton.setChecked(false);
					MyRenderer.setModelViewMode("Polygons");
				}			
			}
		});
        
        modelDirChooserButton.setOnClickListener(new View.OnClickListener() {
			private String settingsViewChosenDir = "";
			private boolean settingsViewNewFolderEnabled = true;
			
			public void onClick(View v) {
				SelectTerrainModelDirectory dirChooserDialogue;
				try {
					dirChooserDialogue = new SelectTerrainModelDirectory(SettingsViewActivity.this, new SelectTerrainModelDirectory.ChosenDirectoryListener() {
						
						public void onChosenDir(String chosenDir) {
							settingsViewChosenDir = chosenDir;
							CameraViewActivity.setModelDirectoryPath(settingsViewChosenDir);
							Toast.makeText(SettingsViewActivity.this, "Chosen directory: " + settingsViewChosenDir, Toast.LENGTH_LONG).show();
						}
					});
					
					dirChooserDialogue.setNewFolderEnabled(settingsViewNewFolderEnabled);
					dirChooserDialogue.chooseDirectory(settingsViewChosenDir);
					settingsViewNewFolderEnabled = !settingsViewNewFolderEnabled;
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}				
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_settings_view, menu);
        return true;
    }
}
